package com.doubleview;


import groovy.lang.Binding;
import groovy.lang.GroovyShell;

/**
 * @author huchengchao@kuaishou.com
 * Created on 2021-11-19
 */
public class GroovyShellExample {

    public static void main(String[] args) {
        Binding binding = new Binding();
        binding.setVariable("x", 10);
        binding.setVariable("language", "Groovy");

        GroovyShell shell = new GroovyShell(binding);
        Object value = shell.evaluate("println \"Welcome to $language\"; y = x * 2; z = x * 3; return x ");

        System.out.println(value + ", " + value.equals(10));
        System.out.println(binding.getVariable("y") + ", " + binding.getVariable("y").equals(20));
        System.out.println(binding.getVariable("z") + ", " + binding.getVariable("z").equals(30));
    }
}